<template>
  <div class="report-designer-container">
    <vab-query-form>
      <vab-query-form-left-panel style="padding-top: 6px">
        <el-descriptions title="美工提成总表" :column="3" border />
      </vab-query-form-left-panel>
      <vab-query-form-right-panel>
        <el-form :inline="true" :model="queryForm" @submit.prevent>
          <el-space>
            <el-form-item label="请选择查询月份">
              <el-date-picker
                v-model="queryForm.month"
                type="month"
                placeholder="请选择月份"
                style="width: 120px"
              />
            </el-form-item>
            <el-form-item>
              <el-select v-model="queryForm.city" style="width: 130px">
                <el-option :value="0" label="请选择区域" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-input
                v-model.trim="queryForm.title"
                clearable
                placeholder="可输入想要查询的关键字"
              />
            </el-form-item>
            <el-form-item>
              <el-button :icon="Search" type="primary" @click="queryData">
                查询
              </el-button>
            </el-form-item>
          </el-space>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>
    <el-tabs type="border-card">
      <el-tab-pane label="首保提成汇总表">
        <el-table>
          <el-table-column label="区域" />
          <el-table-column label="主管组" />
          <el-table-column label="工号" />
          <el-table-column label="美工" />
          <el-table-column label="店铺个数" />
          <el-table-column label="首页个数" />
          <el-table-column label="首保提成" />
          <el-table-column label="详情页模板" />
          <el-table-column label="详情页提成" />
          <el-table-column label="产品上传" />
          <el-table-column label="上传提成" />
          <el-table-column label="海报张数" />
          <el-table-column label="海报提成" />
          <el-table-column label="总提成" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="首保提成明细表">
        <el-table>
          <el-table-column label="序号" width="60" />
          <el-table-column label="店铺名称" />
          <el-table-column label="接单时间" />
          <el-table-column label="工号" />
          <el-table-column label="美工" />
          <el-table-column label="主管组" />
          <el-table-column label="区域" />
          <el-table-column label="产品套餐" />
          <el-table-column label="店铺个数" />
          <el-table-column label="首页个数" />
          <el-table-column label="首页单价" />
          <el-table-column label="首保提成" />
          <el-table-column label="详情页模板" width="120" />
          <el-table-column label="详情页单价" width="120" />
          <el-table-column label="详情页提成" width="120" />
          <el-table-column label="产品上传" />
          <el-table-column label="标准条数" />
          <el-table-column label="上传单价" />
          <el-table-column label="上传提成" />
          <el-table-column label="本月已发条数" width="120" />
          <el-table-column label="海报张数" />
          <el-table-column label="海报单价" />
          <el-table-column label="海报提成" />
          <el-table-column label="总提成" />
          <el-table-column label="备注" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="运营提成汇总表">
        <el-table>
          <el-table-column label="区域" />
          <el-table-column label="主管组" />
          <el-table-column label="工号" />
          <el-table-column label="美工" />
          <el-table-column label="店铺个数" />
          <el-table-column label="首页个数" />
          <el-table-column label="首保提成" />
          <el-table-column label="详情页模板" />
          <el-table-column label="详情页提成" />
          <el-table-column label="产品上传" />
          <el-table-column label="上传提成" />
          <el-table-column label="海报张数" />
          <el-table-column label="海报提成" />
          <el-table-column label="总提成" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="运营提成明细表">
        <el-table>
          <el-table-column label="序号" width="60" />
          <el-table-column label="店铺名称" />
          <el-table-column label="接单时间" />
          <el-table-column label="工号" />
          <el-table-column label="美工" />
          <el-table-column label="主管组" />
          <el-table-column label="区域" />
          <el-table-column label="产品套餐" />
          <el-table-column label="店铺个数" />
          <el-table-column label="首页个数" />
          <el-table-column label="首页单价" />
          <el-table-column label="首保提成" />
          <el-table-column label="详情页模板" width="120" />
          <el-table-column label="详情页单价" width="120" />
          <el-table-column label="详情页提成" width="120" />
          <el-table-column label="产品上传" />
          <el-table-column label="标准条数" />
          <el-table-column label="上传单价" />
          <el-table-column label="上传提成" />
          <el-table-column label="本月已发条数" width="120" />
          <el-table-column label="海报张数" />
          <el-table-column label="海报单价" />
          <el-table-column label="海报提成" />
          <el-table-column label="总提成" />
          <el-table-column label="备注" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="淘宝提成汇总表">
        <el-table>
          <el-table-column label="区域" />
          <el-table-column label="主管组" />
          <el-table-column label="工号" />
          <el-table-column label="美工" />
          <el-table-column label="店铺个数" />
          <el-table-column label="首页个数" />
          <el-table-column label="首保提成" />
          <el-table-column label="详情页模板" />
          <el-table-column label="详情页提成" />
          <el-table-column label="产品上传" />
          <el-table-column label="上传提成" />
          <el-table-column label="海报张数" />
          <el-table-column label="海报提成" />
          <el-table-column label="总提成" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="淘宝提成明细表">
        <el-table>
          <el-table-column label="序号" width="60" />
          <el-table-column label="店铺名称" />
          <el-table-column label="接单时间" />
          <el-table-column label="工号" />
          <el-table-column label="美工" />
          <el-table-column label="主管组" />
          <el-table-column label="区域" />
          <el-table-column label="产品套餐" />
          <el-table-column label="店铺个数" />
          <el-table-column label="首页个数" />
          <el-table-column label="首页单价" />
          <el-table-column label="首保提成" />
          <el-table-column label="详情页模板" width="120" />
          <el-table-column label="详情页单价" width="120" />
          <el-table-column label="详情页提成" width="120" />
          <el-table-column label="产品上传" />
          <el-table-column label="标准条数" />
          <el-table-column label="上传单价" />
          <el-table-column label="上传提成" />
          <el-table-column label="本月已发条数" width="120" />
          <el-table-column label="海报张数" />
          <el-table-column label="海报单价" />
          <el-table-column label="海报提成" />
          <el-table-column label="总提成" />
          <el-table-column label="备注" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="抖店提成汇总表">
        <el-table>
          <el-table-column label="区域" />
          <el-table-column label="主管组" />
          <el-table-column label="工号" />
          <el-table-column label="美工" />
          <el-table-column label="店铺个数" />
          <el-table-column label="首页个数" />
          <el-table-column label="首保提成" />
          <el-table-column label="详情页模板" />
          <el-table-column label="详情页提成" />
          <el-table-column label="产品上传" />
          <el-table-column label="上传提成" />
          <el-table-column label="海报张数" />
          <el-table-column label="海报提成" />
          <el-table-column label="总提成" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="抖店提成明细表">
        <el-table>
          <el-table-column label="序号" width="60" />
          <el-table-column label="店铺名称" />
          <el-table-column label="接单时间" />
          <el-table-column label="工号" />
          <el-table-column label="美工" />
          <el-table-column label="主管组" />
          <el-table-column label="区域" />
          <el-table-column label="产品套餐" />
          <el-table-column label="店铺个数" />
          <el-table-column label="首页个数" />
          <el-table-column label="首页单价" />
          <el-table-column label="首保提成" />
          <el-table-column label="详情页模板" width="120" />
          <el-table-column label="详情页单价" width="120" />
          <el-table-column label="详情页提成" width="120" />
          <el-table-column label="产品上传" />
          <el-table-column label="标准条数" />
          <el-table-column label="上传单价" />
          <el-table-column label="上传提成" />
          <el-table-column label="本月已发条数" width="120" />
          <el-table-column label="海报张数" />
          <el-table-column label="海报单价" />
          <el-table-column label="海报提成" />
          <el-table-column label="总提成" />
          <el-table-column label="备注" />
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <edit ref="editRef" @fetch-data="fetchData" />
  </div>
</template>

<script>
  import { getList, doDelete } from '@/api/reportDesigner'
  import Edit from './components/ReportDesignerEdit'
  import { Delete, Plus, Search } from '@element-plus/icons-vue'

  export default defineComponent({
    name: 'ReportDesigner',
    components: { Edit },
    setup() {
      const $baseConfirm = inject('$baseConfirm')
      const $baseMessage = inject('$baseMessage')

      const state = reactive({
        editRef: null,
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          month: '2024-04',
          city: 0,
          pageNo: 1,
          pageSize: 10,
          title: '',
        },
      })

      const setSelectRows = (val) => {
        state.selectRows = val
      }
      const handleEdit = (row) => {
        if (row.id) {
          state.editRef.showEdit(row)
        } else {
          state.editRef.showEdit()
        }
      }
      const handleDelete = (row) => {
        if (row.id) {
          $baseConfirm('你确定要删除当前项吗', null, async () => {
            const { msg } = await doDelete({ ids: row.id })
            $baseMessage(msg, 'success', 'vab-hey-message-success')
            await fetchData()
          })
        } else {
          if (state.selectRows.length > 0) {
            const ids = state.selectRows.map((item) => item.id).join()
            $baseConfirm('你确定要删除选中项吗', null, async () => {
              const { msg } = await doDelete({ ids })
              $baseMessage(msg, 'success', 'vab-hey-message-success')
              await fetchData()
            })
          } else {
            $baseMessage('未选中任何行', 'error', 'vab-hey-message-error')
          }
        }
      }
      const handleSizeChange = (val) => {
        state.queryForm.pageSize = val
        fetchData()
      }
      const handleCurrentChange = (val) => {
        state.queryForm.pageNo = val
        fetchData()
      }
      const queryData = () => {
        state.queryForm.pageNo = 1
        fetchData()
      }
      const fetchData = async () => {
        state.listLoading = true
        const {
          data: { list, total },
        } = await getList(state.queryForm)
        state.list = list
        state.total = total
        state.listLoading = false
      }
      onMounted(() => {
        fetchData()
      })

      return {
        ...toRefs(state),
        setSelectRows,
        handleEdit,
        handleDelete,
        handleSizeChange,
        handleCurrentChange,
        queryData,
        fetchData,
        Delete,
        Plus,
        Search,
      }
    },
  })
</script>
